<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
test(() => assert_selection(
    '<div contenteditable><span>|XXXX</span></div>',
    selection => {
        for (var i = 0; i < 3; ++i)
            selection.document.execCommand('insertText', false, 'a');
        for (var i = 0; i < 2; ++i)
            selection.modify('move', 'forward', 'character');
        for (var i = 0; i < 3; ++i)
            selection.document.execCommand('insertText', false, 'b');
        for (var i = 0; i < 2; ++i)
            selection.modify('move', 'forward', 'character');
        for (var i = 0; i < 3; ++i)
            selection.document.execCommand('insertText', false, 'c');
    },
    '<div contenteditable><span>aaaXXbbbXXccc|</span></div>'),
    'Typing simulation 1');

test(() => assert_selection(
    '<div contenteditable>|Foo    <i>  bar</i></div>',
    selection => {
        for (var i = 0; i < 4; ++i)
            selection.modify('move', 'forward', 'character');
        for (var i = 0; i < 3; ++i)
            selection.document.execCommand('insertText', false, 'x');
    },
    '<div contenteditable>Foo xxx|<i>bar</i></div>'),
    'Typing simulation 2');

test(() => assert_selection(
    '<div contenteditable><span>|</span></div>',
    selection => {
        function typeWord(n) {
            for (var i = 0; i < n; ++i)
                selection.document.execCommand('insertText', false, 'x');
            selection.document.execCommand('insertText', false, ' ');
        }
        typeWord(4);
        typeWord(1);
        typeWord(2);
    },
    '<div contenteditable>xxxx x xx\u{00A0}|<span></span></div>'),
    'Typing simulation 3');
</script>
